package tk.mybatis.springboot.wexin.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.sf.json.JSONObject;
import tk.mybatis.mapper.util.StringUtil;
import tk.mybatis.springboot.api.controller.BaseController;
import tk.mybatis.springboot.share.util.DateUtils;
import tk.mybatis.springboot.share.util.RedisUtils;
import tk.mybatis.springboot.share.util.WeixinUtil;
import tk.mybatis.springboot.wexin.service.WeixinService;

@Service
@Transactional
public class WeixinServiceImpl implements WeixinService{
	@Override
	public JSONObject createMenu() throws Exception {
		String accessToken = RedisUtils.getStr("accessToken");
		if(StringUtil.isEmpty(accessToken)){
			accessToken = WeixinUtil.getAccessToken().getToken();
			RedisUtils.setStr("accessToken", accessToken, DateUtils.tow_day);
		}	
		int request = WeixinUtil.createMenu(accessToken);
		if(request == 0){
			return BaseController.success("创建菜单成功");
		}else{
			return BaseController.error("创建菜单失败");
		} 
	}

	@Override
	public JSONObject createCustom(String json) {
		// TODO Auto-generated method stub
		return null;
	}
}
